﻿namespace Atlantis.Net.Teamspeak
{
    using Atlantis;
    using Atlantis.Linq;

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Net;
    using System.Net.Sockets;
    using System.Text;
    using System.Threading;

    // username: serveradmin
    // password: CZYYScug

    public class TeamspeakClient : IAPIClient
    {
        #region Fields

        private Thread m_Thread = null;
        private NetworkStream m_Stream = null;

        #endregion

        #region Properties

        private bool m_AutoUpdate = true;
        /// <summary>
        ///     Gets or sets a value indicating whether to auto-update internal collections
        /// </summary>
        public bool AutoUpdate
        {
            get { return m_AutoUpdate; }
            set { m_AutoUpdate = value; }
        }

        private TcpClient m_Client = null;
        /// <summary>
        ///     Gets the underlying TcpClient powering the TeamspeakClient
        /// </summary>
        public TcpClient Client
        {
            get { return m_Client; }
            private set { m_Client = value; }
        }

        private Encoding m_Encoding = Encoding.ASCII;
        /// <summary>
        ///     Gets or sets the encoding of the socket I/O streams
        /// </summary>
        public Encoding Encoding
        {
            get { return m_Encoding; }
            set { m_Encoding = value; }
        }

        private string m_Host = String.Empty;
        /// <summary>
        ///     Gets or sets the Host of for the socket to connect to.
        /// </summary>
        public string Host
        {
            get { return m_Host; }
            set { m_Host = value; }
        }

        private int m_Interval = 60;
        /// <summary>
        ///     Gets or sets the auto-update interval
        /// </summary>
        public int Interval
        {
            get { return m_Interval; }
            set { m_Interval = value; }
        }

        /// <summary>
        ///     Gets or sets a value indicating whether the thread is a background thread or active
        /// </summary>
        public bool IsBackground
        {
            get { return m_Thread.IsBackground; }
            set
            {
                if (m_Thread != null && !m_Thread.IsAlive)
                {
                    m_Thread.IsBackground = value;
                }
            }
        }

        /// <summary>
        ///     Gets a value indicating whether the TeamspeakClient has been initialized
        /// </summary>
        public bool IsInitialized
        {
            get
            {
                bool ret = true;

                return ret;
            }
        }

        private string m_Login = String.Empty;
        /// <summary>
        ///     Gets or sets the login name for the server query session
        /// </summary>
        public string Login
        {
            get { return m_Login; }
            set { m_Login = value; }
        }

        private int m_Port = 10011;
        /// <summary>
        ///     Gets or sets the Server Query Port
        /// </summary>
        public int Port
        {
            get { return m_Port; }
            set { m_Port = value; }
        }

        private string m_Password = String.Empty;
        /// <summary>
        ///     Gets or sets the password for the server query session
        /// </summary>
        public string Password
        {
            get { return m_Password; }
            set { m_Password = value; }
        }

#if DEBUG
        private bool m_WriteLog = true;
#else
        private bool m_WriteLog = false;
#endif
        /// <summary>
        ///     <para>Gets or sets a value indicating whether to write TS3 output to a logfile</para>
        /// </summary>
        /// <devdoc>This will default to true if compiled as a DEBUG build.</devdoc>
        public bool WriteLog
        {
            get { return m_WriteLog; }
            set { m_WriteLog = value; }
        }

        #endregion

        #region Methods

        public bool Disconnect()
        {
            return false;
        }


        protected virtual void OnDataReceive(string data)
        {
            //
        }

        public bool Send(string data, params object[] args)
        {
            return false;
        }

        public void Start()
        {
            if (!IsInitialized)
            {
                throw new NotImplementedException("TeamspeakClient has not been initialized. Please check your settings and try again.");
            }


        }

        public void Stop()
        {
        }

        private void ThreadCallback()
        {
            //
        }

        #endregion

    }
}
